package com.fuhaiwei.struts.action.impl;

import com.fuhaiwei.basic.utils.TextUtils;
import com.fuhaiwei.domain.service.ModifyResult;
import com.fuhaiwei.struts.action.ModifyAction;

public class ModifyActionImpl extends ModifyAction {

	public String execute() throws Exception {
		ModifyResult result = getModifyService().doModify(getUsername(),
				getOldpassword(), getNewpassword());
		if (result == ModifyResult.MODIFY_SUCCESS) {
			getSession().remove(SESSION_USER_NAME);
			return SUCCESS;
		}
		if (result == ModifyResult.PASSWORD_WORNG) {
			setTip(getTextUtils().text(TextUtils.INPUT_WRONG,
					getTextUtils().label(PASSWORD)));
			return INPUT;
		}
		if (result == ModifyResult.USERNAME_NOTEXISTS) {
			setTip(getTextUtils().text(TextUtils.INPUT_NOTEXISTS,
					getTextUtils().label(USERNAME)));
			return INPUT;
		}
		if (result == ModifyResult.DATABASE_ERROR) {
			setTip(getTextUtils().text(TextUtils.ERROR_DATABASE));
			return INPUT;
		}
		setTip(getTextUtils().text(TextUtils.ERROR_RETURN));
		return INPUT;
	}

}
